package ch6;

import java.util.Scanner;

public class InsertToArray {

	public static void main(String[] args) {
		// 插入新值到数组
		int ar[] = new int[] { 99, 86, 78, 69, 54, 0 };
		// 0这个成绩没有，ar只存了5个值
		Scanner in = new Scanner(System.in);
		System.out.println("请输入第六个成绩：");
		int k = in.nextInt();
		// 找位置
		int pos = 0;
		while (pos < ar.length - 1) {
			if (ar[pos] < k)
				break;
			pos++;
		}
		System.out.println(pos + "是新数的位置：");
		// 从pos到ar.length-2上的数，都要后移一位
		for (int j = ar.length - 2; j >= pos; j--) {
			ar[j + 1] = ar[j];
		}
		ar[pos] = k;
		for (int i : ar)
			System.out.print(i + " ");
	}

}
